package com.wx.mall.operate.controller;


import com.wx.mall.common.api.CommonPage;
import com.wx.mall.common.api.CommonResult;
import com.wx.mall.common.api.ResultCode;
import com.wx.mall.common.exceptions.ApiAssert;
import com.wx.mall.operate.dto.SeckillAddsDto;
import com.wx.mall.operate.entity.SeckillAdds;
import com.wx.mall.operate.service.impl.SeckillAddsServiceImpl;
import com.wx.mall.operate.vo.SeckillAddsReqVo;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author j
 * @since 2020-05-28
 */
@RestController
@RequestMapping("/seckill/adds")
public class SeckillAddsController {

    @Autowired
    SeckillAddsServiceImpl seckillAddsService;

    @ApiOperation(value = "分页查询")
    @GetMapping("/getSecAddsPages")
    public CommonResult<CommonPage<SeckillAdds>> getFindSecAddsList(SeckillAddsDto dto){
        if (dto.getPageNum() == null || dto.getPageSize() == null){
            ApiAssert.fail(ResultCode.VALIDATE_FAILED);
        }
        if (dto.getPageNum() == 0){
            ApiAssert.fail("无效页码");
        }
        List<SeckillAdds> list=seckillAddsService.findSecAddsList(dto);
        return CommonResult.success(CommonPage.restPage(list));
    }

    @ApiOperation(value = "筛选查询")
    @GetMapping("/getSecAddsTwoPages")
    public CommonResult<CommonPage<SeckillAdds>> getFindSecAddsTwoList(SeckillAddsDto dto){
        if (dto.getPageNum() == null || dto.getPageSize() == null){
            ApiAssert.fail(ResultCode.VALIDATE_FAILED);
        }
        if (dto.getPageNum() == 0){
            ApiAssert.fail("无效页码");
        }
        List<SeckillAdds> list=seckillAddsService.findSecAddsTwoList(dto);
        return CommonResult.success(CommonPage.restPage(list));
    }

    @ApiModelProperty(value = "跳转添加")
    @PostMapping("/getAddToItem")
    public CommonResult<Integer> getAddToItemList(SeckillAddsReqVo ids){
        int i = seckillAddsService.addsToItem(ids);
        return i==1?CommonResult.success():CommonResult.failed();
    }
}

